/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BuscarEmpleado.java
 *
 * Created on 10/01/2009, 09:36:39 PM
 */
package UIDelNegocio;

import LogicaDeNegocio.Empleado;
import LogicaDeNegocio.Main;
import javax.swing.JOptionPane;

/**
 *
 * @author Anya
 */
public class BuscarEmpleado extends javax.swing.JFrame {

    public static String name = "";
    public static String tipo = "";
    public static int opc;

    /** Creates new form BuscarEmpleado */
    public BuscarEmpleado(String name1, String tipo1, int opc1) {
        name = name1;
        tipo = tipo1;
        opc = opc1;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jLabel26 = new javax.swing.JLabel();
        jLabel27 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("WellDresing");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Verdana", 1, 10));
        jLabel1.setText("Buscar Empleados");

        jLabel2.setText("N° Cedula");

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UIDelNegocio/buscar.png"))); // NOI18N
        jLabel3.setText("Buscar");
        jLabel3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel3MouseClicked(evt);
            }
        });

        jLabel4.setText("Nombre:");

        jLabel5.setText("Apellido:");

        jLabel8.setText("Sexo:");

        jLabel6.setText("Cedula:");

        jLabel9.setText("Estado Civil:");

        jLabel7.setText("Fecha de Nacimiento:");

        jLabel12.setText("Nivel de estudio:");

        jLabel10.setText("Direccion:");

        jLabel11.setText("Sueldo:");

        jLabel13.setText("Telefono:");

        jLabel14.setText("Cargo:");

        jLabel15.setText("Fecha de entrada:");

        jLabel16.setText("jLabel16");

        jLabel17.setText("jLabel16");

        jLabel18.setText("jLabel16");

        jLabel19.setText("jLabel16");

        jLabel20.setText("jLabel16");

        jLabel21.setText("jLabel16");

        jLabel22.setText("jLabel16");

        jLabel23.setText("jLabel16");

        jLabel24.setText("jLabel16");

        jLabel25.setText("jLabel16");

        jLabel26.setText("jLabel16");

        jLabel27.setText("jLabel16");

        jButton1.setText("Cerrar");
        jButton1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(60, 60, 60)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel14)
                                    .addComponent(jLabel15)
                                    .addComponent(jLabel11)
                                    .addComponent(jLabel13)
                                    .addComponent(jLabel10)
                                    .addComponent(jLabel12)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel9)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel5))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel26)
                                    .addComponent(jLabel27)
                                    .addComponent(jLabel25)
                                    .addComponent(jLabel16)
                                    .addComponent(jLabel23)
                                    .addComponent(jLabel24)
                                    .addComponent(jLabel22)
                                    .addComponent(jLabel20)
                                    .addComponent(jLabel21)
                                    .addComponent(jLabel19)
                                    .addComponent(jLabel18)
                                    .addComponent(jLabel17)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel3)))))
                .addContainerGap(113, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(277, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(73, 73, 73))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(jLabel8))
                .addGap(7, 7, 7)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel20)
                            .addComponent(jLabel9))
                        .addGap(12, 12, 12)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel21)
                            .addComponent(jLabel7)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel19)
                            .addComponent(jLabel6))
                        .addGap(50, 50, 50)))
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(102, 102, 102)
                        .addComponent(jLabel14)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel15))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel23)
                                    .addComponent(jLabel10))
                                .addGap(12, 12, 12)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel24)
                                    .addComponent(jLabel11)))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel22)
                                    .addComponent(jLabel12))
                                .addGap(50, 50, 50)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel26)
                                .addGap(12, 12, 12)
                                .addComponent(jLabel27))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel25)
                                    .addComponent(jLabel13))
                                .addGap(50, 50, 50)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 59, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        Main ma = new Main();
        /*if (opc==1)
        {
        Empleado a = (Empleado)ma.consultarEmpleado(Integer.parseInt(jTextField1.getText()));
        jLabel16.setText(a.getNombre());
        jLabel17.setText(a.getApellido());
        jLabel18.setText(a.getSexo());
        jLabel19.setText(String.valueOf(a.getCi()));
        jLabel20.setText(a.getEstadoCivil());
        jLabel21.setText("12-12-1111");//(a.getFechaNacimiento());
        jLabel22.setText(a.getNivelEstudios());
        jLabel23.setText(a.getDireccion());
        jLabel24.setText(String.valueOf(a.getSueldo()));
        jLabel25.setText(a.getTelefono());
        jLabel26.setText(a.getCargo());
        jLabel27.setText("12-12-1111");//(a.getFechaEntrada());
        }
        else
        {
        ma.borrarEmpleado(Integer.parseInt(jLabel19.getText()));
        }*/

        //if(jButton1.getText().compareTo("Eliminiar")== 0)
        if (opc != 1) {
            ma.borrarEmpleado(Integer.parseInt(jLabel19.getText()));
        }

        Adminis vent = new Adminis(name, tipo);
        this.setVisible(false);
        vent.setVisible(true);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        if (opc == 1) {
            jButton1.setText("Cerrar");
            jLabel1.setText("Buscar Empleados");
        } else {
            jLabel1.setText("Eliminar Empleados");
            jButton1.setText("Eliminar");
        }
    }//GEN-LAST:event_formWindowActivated

    private void jLabel3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel3MouseClicked

        Main control = new Main();
        Main ma = new Main();

        Empleado a = new Empleado();

        a = (Empleado) ma.consultarEmpleado(Integer.parseInt(jTextField1.getText()));
        String p = a.getNombre();
        System.out.println(p);
        //System.out.println(a.getNombre());
        if (p.compareTo("null") == 0) {
            JOptionPane.showMessageDialog(this, "Producto ya existente", "WellDressing", JOptionPane.ERROR_MESSAGE);


            a = (Empleado) ma.consultarEmpleado(Integer.parseInt(jTextField1.getText()));
            if (a != null) //System.out.println(a.getNombre());
            //System.out.println(a.getFechaNacimiento());
            {
                String fecha1 = a.getFechaNacimiento().getDate() + "-" + (a.getFechaNacimiento().getMonth() + 1) + "-" + (a.getFechaNacimiento().getYear() + 1900);

                String fecha2 = a.getFechaEntrada().getDate() + "-" + (a.getFechaEntrada().getMonth() + 1) + "-" + (a.getFechaEntrada().getYear() + 1900);
            // String fecha3 = a.getFechaEntrada().getDate()+"-"+(a.getFechaEntrada().getMonth()+1)+"-"+(a.getFechaEntrada().getYear()+1900);
            } else {


                //System.out.println(a.getNombre());
                //System.out.println(a.getFechaNacimiento());

                String fecha1 = a.getFechaNacimiento().getDate() + "-" + (a.getFechaNacimiento().getMonth() + 1) + "-" + (a.getFechaNacimiento().getYear() + 1900);

                String fecha2 = a.getFechaEntrada().getDate() + "-" + (a.getFechaEntrada().getMonth() + 1) + "-" + (a.getFechaEntrada().getYear() + 1900);
                // String fecha3 = a.getFechaEntrada().getDate()+"-"+(a.getFechaEntrada().getMonth()+1)+"-"+(a.getFechaEntrada().getYear()+1900);

                jLabel16.setText(a.getNombre());
                jLabel17.setText(a.getApellido());
                jLabel18.setText(a.getSexo());
                jLabel19.setText(String.valueOf(a.getCi()));
                jLabel20.setText(a.getEstadoCivil());
                jLabel21.setText(fecha1);
                jLabel22.setText(a.getNivelEstudios());
                jLabel23.setText(a.getDireccion());
                jLabel24.setText(String.valueOf(a.getSueldo()));
                jLabel25.setText(a.getTelefono());
                jLabel26.setText(a.getCargo());
                jLabel27.setText(fecha2);

            }
        }
        else  {
            JOptionPane.showMessageDialog(this, "El empleado no existe", "WellDressing", JOptionPane.ERROR_MESSAGE);
        }
    
    }//GEN-LAST:event_jLabel3MouseClicked
/**
 * @param args the command line arguments

public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new BuscarEmpleado().setVisible(true);
}
});
}*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
}
